package cn.itsource.org.controller;


import cn.itsource.org.domain.Department;
import cn.itsource.org.query.BaseQuey;
import cn.itsource.org.service.Departservice;
import cn.itsource.org.util.JSONResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RequestMapping("/dept")
@RestController
@Api(value = "部门接口管理文档",description = "部门接口管理")
public class DepartmentController {
    @Autowired
    Departservice departservice;
        /**
        *1.请求方式: post
        *2.url:/dept/findPage
        *3.请求参数:无
        *4.响应参数:baseQuey
        **/
        //高级查询
    @PostMapping("/findPage")
    @ApiOperation(value = "查询所有用户",notes = "查询所有用户")
    public JSONResult list(@RequestBody BaseQuey baseQuey){

        return departservice.findPage(baseQuey);
    }
            /**
            *1.请求方式: Get
            *2.url:/dept/findtree
            *3.请求参数:无
            *4.响应参数: findAll
            **/

            //级联
    @GetMapping("/findtree")
    public JSONResult findtree(){
        return departservice.findtree();
    }
               /**
                *1.请求方式: Post
                *2.url:/dept/add
                *3.请求参数:department
                *4.响应参数:department
                **/
               //新增
    @PostMapping("/add")
    public JSONResult add(@RequestBody @Valid Department department){

        return departservice.add(department);
    }
        /**
            *1.请求方式:
            *2.url:
            *3.请求参数:
            *4.响应参数:
            **/
    @PostMapping("/update")
    public JSONResult update(@RequestBody @Valid Department department){
        return departservice.update(department);
    }


    @PostMapping("/delete/{id}")
    public JSONResult delete(@PathVariable("id") Long id){
        return departservice.delete(id);
    }
    @PostMapping("/deletebatch")
    public JSONResult deletebatch(@RequestBody List<Long> ids){
        return departservice.deletebatch(ids);
    }
}
